package zx.x.modules.yshbms.controller;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import zx.x.common.utils.PageUtils;
import zx.x.common.utils.R;
import zx.x.modules.app.entity.UserEntity;
import zx.x.modules.yshapp.dto.UserVo;
import zx.x.modules.yshapp.entity.CommunityBulletinEntity;
import zx.x.modules.yshapp.entity.CommunityEntity;
import zx.x.modules.yshapp.vo.User2Vo;
import zx.x.modules.yshbms.service.CommunityService;
import zx.x.modules.yshbms.service.UserService;

import java.util.Map;


/**
 *社区公告
 */
@RestController
@RequestMapping("yshbms/user")
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
    private CommunityService communityService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = userService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		UserEntity userEntity = userService.getById(id);
        if(userEntity != null){
            userEntity.setPassword(null);
            userEntity.setOpenid(null);
            userEntity.setSessionKey(null);
            userEntity.setCode(null);
            userEntity.setToken(null);
        }

        User2Vo user2Vo = new User2Vo();
        BeanUtils.copyProperties(userEntity, user2Vo);
        CommunityEntity communityEntity = communityService.getById(userEntity.getCommunityId());
        user2Vo.setCommunityName(communityEntity.getCommunityName());
        return R.ok().put("userEntity", user2Vo);
    }



    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody UserEntity userEntity){

        userService.updateById(userEntity);
        return R.ok();
    }



}
